// 需求：定义Person类，属性：名字和年龄，方法：吃饭
// 需求：定义Person类，属性：名字和年龄，方法：吃饭
void main() {
  // Person man = Person('zhangsan', 18, '男');
  // man.intro();

  // Person man = Person(name: '张三丰', age: 18, gender: '男');
  // man.intro();
  // Person man = Person(name: '张三丰', age: 18, gender: '男');
  // man.intro();

  Person woman = Person(18, '男', '王');
  woman.intro();

  Person woman1 = Person.init('王大龙', 18);
  woman1.intro();

  Person woman2 = Person.creat('王1龙');
  woman2.intro();
}

class Person {
  // 属性
  String? name;
  int? age;
  String? gender;

  // 主构造函数
  // Person({String? name, int? age, String? gender}) {
  //   print('这是主构造函数');
  //   this.name = name;
  //   this.age = age;
  //   this.gender = gender;
  // }
  //简写
  Person(this.age, this.gender, this.name);

  //次构造函数(可以一主多次)
  // Person.init(String name, int age) {
  //   print('这是次构造函数');
  //   this.name = name;
  //   this.age = age;
  //   this.gender = '男';
  // }
  //简写
  Person.init(this.name, this.age) : this.gender = '男';

  // Person.creat(String name) {
  //   print('这是次构造函数');
  //   this.name = name;
  //   this.age = 29;
  //   this.gender = '女';
  // }
  //简写
  Person.creat(this.name)
      : this.age = 29,
        this.gender = '女';

  // 方法
  intro() {
    print('我的名字是$name,年龄是$age,性别是$gender');
  }
}
